"""
---------------------------------------------------------------------
- File: sqlmode_base.py
- Date: 2025/11/17
- Author: yangzhide
- Email: xxzjyzd@126.com
- Description: 基础sqlmodel， 便于其他model/schema继承
---------------------------------------------------------------------
"""

from datetime import datetime
from typing import Generic, TypeVar, List

from sqlalchemy import func
from sqlmodel import SQLModel, Field

T = TypeVar("T")


class IdTimeModel(SQLModel):
    """
    主键ID/创建时间/更新时间模型
    """

    id: int | None = Field(None, primary_key=True, description="主键ID")
    create_time: datetime | None = Field(
        None,
        sa_column_kwargs={"server_default": func.now(), "comment": "创建时间"},
        description="创建时间",
    )
    update_time: datetime | None = Field(
        None,
        sa_column_kwargs={"server_default": func.now(), "onupdate": func.now(), "comment": "更新时间"},
        description="更新时间",
    )


class PageModel(SQLModel, Generic[T]):
    """
    通用分页结构模型
    """

    list: List[T] = Field(default_factory=list, description="数据列表")
    total: int = Field(default=0, description="总数", alias="total")
